package com.nut.spp.service.impl;

import com.nut.spp.common.Result;
import com.nut.spp.entity.MemberAddress;
import com.nut.spp.mapper.MemberAddressMapper;
import com.nut.spp.service.MemberAddressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;
import java.util.Set;

@Service
@Slf4j
public class MemberAddressServiceImpl implements MemberAddressService {

    @Autowired
    private MemberAddressMapper memberAddressMapper;

    @Override
    public Result<List<MemberAddress>> list(Long memberId) {
        List<MemberAddress> list = memberAddressMapper.selectByMemberId(memberId);
        return Result.ok(list);
    }

    @Override
    public Result<MemberAddress> getById(Serializable id) {
        MemberAddress memberAddress = memberAddressMapper.selectById(id);
        return Result.ok(memberAddress);
    }

    @Override
    public Result add(MemberAddress memberAddress) {
        memberAddressMapper.insert(memberAddress);
        return Result.ok();
    }

    @Override
    public Result updateById(MemberAddress memberAddress) {
        memberAddressMapper.updateById(memberAddress);
        return Result.ok();
    }

    @Override
    public Result deleteByIds(Set<Integer> ids) {
        for (Integer id : ids) {
            memberAddressMapper.deleteById(id);
        }
        return Result.ok();
    }
}